<template>
  <el-container class="container">
    <el-header class="el-header">
      <div class="logo">MDF</div>
      <div class="bar">
        <i></i>
        <div>
          <el-badge class="badge-box" :value="3">
            <el-button type="text">重要通知</el-button>
          </el-badge>
          <el-dropdown>
            <span class="el-dropdown-link">
              admin
              <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </el-header>
    <el-container class="main-container">
      <el-aside class="aside">
        <el-menu :default-active="activeIndex" class="el-menu-vertical-demo" :collapse="isCollapse" router>
          <template :index='item.id' v-for="item in navData">
            <el-menu-item :index='item.id' :key="item.id" v-if="!item.subNav.length">
              <span slot="title">{{item.title}}</span>
            </el-menu-item>
            <el-submenu :index='item.id' :key="`sub-${item.id}`" v-else>
              <template slot="title">
                <span>{{item.title}}</span>
              </template>
              <el-menu-item v-for="ceil in item.subNav" :key="ceil.id" :index="ceil.url">{{ceil.title}}</el-menu-item>
            </el-submenu>

          </template>
        </el-menu>
      </el-aside>
      <el-main class="main">

        <transition name="el-fade-in">
          <keep-alive>
            <router-view></router-view>
          </keep-alive>
        </transition>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { api, navData } from '@/utils'
export default {
  data () {
    return {
      isCollapse: false,
      title: '',
      listData: [],
      navData: navData
    }
  },
  computed: {
    activeIndex () {
      let index = this.$route.params.id
      if (typeof index === 'number') {
        index = index.toString()
      }
      return index
    },
    breadData () {
      return this.$store.state.breadData
    }
  },
  created () {
    /* 请求样例 */
    this.$axios.get(api.login, {
      params: {
        page: 0,
        size: 100
      }
    })
    this.$axios.post(api.login, {
      page: 0,
      size: 100
    }
    )
    /* 请求样例 */
  }
}

</script>

<style scoped lang="scss">
$width: 200px;
.badge-box {
  margin-right: 10px;
  button {
    color: $light;
  }
}
.el-header {
  padding: 0;
  display: flex;
}
.logo {
  height: 100%;
  background: $color-primary;
  width: $width;
  font-size: 20px;
  text-align: center;
  color: $light;
  line-height: 60px;
  border-right: 1px solid rgba(255, 255, 255, 0.3);
}
.bar {
  background: $color-primary;
  height: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  color: $light;
  padding: 0 20px;
  justify-content: space-between;
  .el-dropdown-link {
    color: $light;
    cursor: pointer;
  }
  .menu {
    font-size: 24px;
  }
}
.container {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.main-container {
  align-items: stretch;
}

.aside {
  width: $width !important;
  background: #eef1f6;
  overflow-x: hidden;
  .el-menu-item {
    overflow: hidden;
    text-overflow: ellipsis;
  }
}
.main {
  padding: 20px;
}
</style>
